<template>
	<view class="container">
		<view class="filter-bar">
			<view class="filter-item" @click="openTitleFilter">
				<text class="filter-title">职称</text>
				<text class="iconfont icon-arrow-down"></text>
			</view>
			<view class="filter-item" @click="openScheduleFilter">
				<text class="filter-title">出诊</text>
				<text class="iconfont icon-arrow-down"></text>
			</view>
			<view class="filter-item" @click="openSortFilter">
				<text class="filter-title">排序</text>
				<text class="iconfont icon-arrow-down"></text>
			</view>
		</view>

		<view class="doctor-list">
			<view class="doctor-item" v-for="doctor in doctorList" :key="doctor.id" @click="goToAppointment(doctor)">
				<image class="doctor-avatar" :src="doctor.avatar" mode="aspectFill"></image>
				<view class="doctor-info">
					<view class="doctor-basic">
						<view class="doctor-name">{{ doctor.name }}</view>
						<view class="doctor-title">{{ doctor.title }}</view>
					</view>
					<view class="doctor-department">{{ dept.name }}</view>
					<view class="doctor-experience">{{ doctor.experience }}</view>
					<view class="doctor-skills">{{ doctor.skills }}</view>
				</view>
				<view class="doctor-right">
					<view class="doctor-rating">
						<text class="iconfont icon-star"></text>
						<text>{{ doctor.rating }}</text>
					</view>
					<view class="appointment-btn">预约</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		DOCTOR_LIST,
		DEPARTMENT_LIST
	} from '@/config.js'
	export default {
		data() {
			return {
				doctorList: DOCTOR_LIST,
				hospitalId: 1,
				deptId: 1,
				dept: {}
			}
		},
		onLoad(options) {
			// 这里可以根据传递的hospitalId和deptId加载对应医生列表
			if (options.hospitalId) this.hospitalId = options.hospitalId
			if (options.deptId) this.deptId = options.deptId
			this.dept = DEPARTMENT_LIST.find(x => x.id == this.deptId)
		},
		methods: {
			openTitleFilter() {
				uni.showActionSheet({
					itemList: ['全部', '主任医师', '副主任医师', '主治医师', '住院医师'],
					success: function(res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			openScheduleFilter() {
				uni.showActionSheet({
					itemList: ['全部', '今天', '明天', '本周内', '下周内'],
					success: function(res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			openSortFilter() {
				uni.showActionSheet({
					itemList: ['推荐排序', '评分优先', '主任医师优先', '近期可约优先'],
					success: function(res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			goToAppointment(doctor) {
				uni.navigateTo({
					url: `/pages/appointment/appointment?doctorId=${doctor.id}&hospitalId=${this.hospitalId}&deptId=${this.deptId}`
				});
			}
		}
	}
</script>

<style scoped>
	.container {
		background-color: #f5f5f5;
	}

	.filter-bar {
		display: flex;
		background-color: #fff;
		padding: 20rpx 0;
	}

	.filter-item {
		flex: 1;
		text-align: center;
		font-size: 28rpx;
		color: #333;
	}

	.filter-item .iconfont {
		font-size: 24rpx;
		margin-left: 6rpx;
	}

	.doctor-list {
		padding: 20rpx;
	}

	.doctor-item {
		display: flex;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
	}

	.doctor-avatar {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
		margin-right: 30rpx;
	}

	.doctor-info {
		flex: 1;
		margin-right: 30rpx;
	}

	.doctor-basic {
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.doctor-name {
		font-size: 32rpx;
		font-weight: bold;
		margin-right: 10px;
	}

	.doctor-title {
		font-size: 24rpx;
		color: #1677ff;
		background-color: #e6f4ff;
		padding: 4rpx 10rpx;
		border-radius: 6rpx;
	}

	.doctor-department {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 6px;
	}

	.doctor-experience {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 6rpx;
	}

	.doctor-skills {
		font-size: 24rpx;
		color: #999;
		line-height: 1.4;
	}

	.doctor-right {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.doctor-rating {
		font-size: 24rpx;
		color: #ff9900;
	}

	.appointment-btn {
		background-color: #1677ff;
		color: #fff;
		font-size: 24rpx;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
	}
</style>